<script setup>
const props = defineProps({
  num: {
    type: Number,
    default: 0,
    required: true,
    validator: value => {
      return value < 5
    }
  }
})
const emits = defineEmits(['setNum'])
const btnClick = () => {
  console.log(props.num)
}
const btnClick2 = () => {
  emits('setNum', props.num + 1)
}
</script>

<template>
  <div class="son-page">
    我是son子组件
    <h2>{{ num }}</h2>
    <button @click="btnClick">打印num</button>
    <button @click="btnClick2">修改num</button>
  </div>
</template>

<style lang="scss" scoped></style>
